package com.office.utils.csv;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class CsvUtil {

    public static String companyNameChange(String str) {
        return str.replace("深圳市", "")
                .replace("深圳", "")
                .replace("有限公司", "")
                .replace("公司", "")
                .replace("先生", "")
                .replace("小姐", "");
    }

    public static String getPhone(String str) {
        Pattern pattern = Pattern.compile("^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(17[013678])|(18[0,5-9]))\\\\d{8}$");
        Matcher matcher = pattern.matcher(str);
        String tmp = "";
        while (matcher.find()) {
            // tmp=tmp+matcher.group();
            System.out.println(matcher.group());
        }
        //System.out.println(res.toString());
        return tmp;

    }

    public static void test() {
        try {
            //先FileReader把文件读出来再bufferReader按行读  reader.readLine(); 没有标题用不着了
            InputStreamReader isr = new InputStreamReader(new FileInputStream("D:\\test.csv"), "gbk");
            BufferedReader reader = new BufferedReader(isr);
            String line = null;
            int index = 0;
            while ((line = reader.readLine()) != null) {
                if (index > 0) {
                    //System.out.println("行：" + line);
                    String[] item = line.split(",");//一行数组
                    String companyName = "";
                    String userName = "";
                    String phone = "";
                    if (item.length > 3) {
                        companyName = null == item[1] ? "客户空" : "客户" + companyNameChange(item[1]);
                        if (null == item[2]) {
                            userName = companyName;
                        } else {
                            userName = item[2];
                        }
                        phone = item[3] == null ? "空号" : item[3];
                    }

                    System.out.println(getPhone(phone) + ":::" + phone);
                    //System.out.println(companyName.replace(" ","")+companyNameChange(userName).replace(" ","")+phone);
                }
                index++;
            }
        } catch (Exception e) {
            //在命令行打印异常信息在程序中出错的位置及原因。
            e.printStackTrace();
        }

    }

    public static void main(String[] args) {
        // test();
        String text = "15989549448";
        getPhone(text);
    }
}
